package cn.qj.ymcc;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.factory.Factory.Payment;
import com.alipay.easysdk.kernel.Config;
import com.alipay.easysdk.kernel.util.ResponseChecker;
import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse;
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        // 1. 设置参数（全局只需设置一次）
        Factory.setOptions(getOptions());
        try {
            AlipayTradePagePayResponse response = Payment.Page().pay("测试",
                    "2010112011",
                    "200.00",
                    "http://www.baidu.com");
            // 3. 处理响应或异常
            if (ResponseChecker.success(response)) {
                System.out.println("调用成功");
            } else {
                System.err.println("调用失败，原因：" + response.getBody());
            }
        } catch (Exception e) {
            System.err.println("调用遭遇异常，原因：" + e.getMessage());
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    private static Config getOptions() {
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi-sandbox.dl.alipaydev.com";
        config.signType = "RSA2"; //加密类型
        config.appId = "9021000150685410";
        // 为避免私钥随源码泄露，推荐从文件中读取私钥字符串而不是写入源码中
        config.merchantPrivateKey = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDXT4US7bdFjPooEbFx8LCdgjKffRJpgu3USzuInRxJQCQiwlMa8Gjd0vGzOk9fvU/LTy1oyKmrA8LVPi4ydLE/QsB4/MTiRMz/i1kJYKMh7oK7vTSAwvqRBqZOjE4mklKNBr9TaPoqBRNFlI/BeyBTU5SbAYkL5BPrc1vvEuwVNEhxhY7ycLTxAbx3FqN/GUuprjvbmUb+O2zxzbeuIFJ38v2MopAwzGsUshlYl/7ktsX/Br/UDLmz0hu5NvEyNgvhWLs6wlNVAWqtbFFg8xxRd6JKRKZrkBcCXyZqqmq9VqxIuTV0wIqz9zf/SGgGdXiD35kCfDy6i2zf7Gdr2aylAgMBAAECggEAATm1oy7xLRcpUVMQdHqPNsZH7XpzwV/6ZI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AWaEYuTYZVPcKI3KQOFWZ7D4eePHZEyZURcexPacmFXOMYYUBsnZEhAozKSoBnUWNM1mg0O+4zkAfBoxUYs+Dxlurs6XNcg/CblFEjFw==";
        //注：证书文件路径支持设置为文件系统中的路径或CLASS_PATH中的路径，优先从文件系统中加载，加载失败后会继续尝试从CLASS_PATH中加载
        config.alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA02bn/Qeu1efBqO/w9BOZVN6Jy4I2WYs2BSTzq5TAX3gRTYk8acj6prLGfCuLGWIF6E4srWLZztjN5cjIU6732Kf7LXI5DdDHBI1XxoRDQ2i984DD1L5U6r4GuWizkn2/nZBikArwbxjqtPVluDbOuKwOKFdgy75p18HPIISQBCBpaS497Ggc2dVcEOEaQN5XtFQjAm0qhgVuFk1MGp/jFzbT1+0noex+/RWL3m3TJXiNsfvc2pYa8RXl3HNzu+aR0QgndQODIybt9YoINtNuOGia6ZlL3tUAihQb2o/Qh100GxYbebtPepoW9staACR4JoxL4Y2Yin0pFiA8EqVWRwIDAQAB";
        //可设置异步通知接收服务地址（可选）
        config.notifyUrl = "http://localhost:10010/xxyy";
        return config;
    }
}